package com.dal.thread;

/**
 * @program: spring-boot
 * @description:
 * @author: jian
 * @create: 2022-03-03 17:57
 **/
public class Demo01 {
    public static final long count = 1000000000;
    //并发时间
    public static void concurrency() throws InterruptedException {
        long start = System.currentTimeMillis();
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                int a = 0;
                for (int i = 0; i < count; i++) {
                    a +=5;
                }
            }
        });
        thread.start();
        int b = 0;
        for (int i = 0; i < count; i++) {
            b--;
        }
        long time = System.currentTimeMillis()-start;
        thread.join();
        System.out.println("time="+time+"ms =====b==="+b);
    }

    /**
     * 串行
     */
    public static void serial(){
        long start = System.currentTimeMillis();
        int a = 0;
        for (int i = 0; i < count; i++) {
            a +=5;
        }
        int b = 0;
        for (int i = 0; i < count; i++) {
            b--;
        }
        long time = System.currentTimeMillis() - start;
        System.out.println("time="+time+"ms ,b="+b+",a="+a);
    }

    public static void main(String[] args) throws InterruptedException {
        concurrency();
        serial();
    }
}
